package com.lwj.liwanjia.view.activity.work;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ListView;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.adapter.WorkHomeTypeAdapter;
import com.lwj.liwanjia.bean.WorkHomeTypeBean;
import com.lwj.liwanjia.utils.GlideImageLoader;
import com.youth.banner.Banner;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 001 on 2017/9/12.
 */

public class CustomListViewWorkHome extends ListView {

    private View headView;//头部局
    private Banner mBanner;//轮播图
    private RecyclerView mRecyclerView;//条目分类
    private List<Integer> bannerList;//轮播图数据
    private List<WorkHomeTypeBean> typeList;//分类的数据
    private WorkHomeTypeAdapter typeAdapter;

    public CustomListViewWorkHome(Context context) {
        this(context, null);
    }

    public CustomListViewWorkHome(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CustomListViewWorkHome(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        initView();
        initData();
    }

    private void initView() {

        headView = View.inflate(getContext(), R.layout.custom_work_home, null);

        mBanner = (Banner) headView.findViewById(R.id.banner);
        mRecyclerView = (RecyclerView) headView.findViewById(R.id.recyclerView);

        addHeaderView(headView);
    }

    private void initData() {

        //设置轮播图
        initBanner();

        //假数据,适配器
        initRecyclerView();
    }

    //设置轮播图
    private void initBanner() {

        //假数据,可删
        bannerList = new ArrayList<>();
        bannerList.add(R.mipmap.work_banner);

        //设置图片加载器
        mBanner.setImageLoader(new GlideImageLoader());
        //设置图片集合
        mBanner.setImages(bannerList);
        //banner设置方法全部调用完毕时最后调用
        mBanner.start();
    }

    //假数据,适配器
    private void initRecyclerView() {

        typeList = new ArrayList<>();
        WorkHomeTypeBean bean01 = new WorkHomeTypeBean();
        bean01.title = "我是房东";
        typeList.add(bean01);

        WorkHomeTypeBean bean02 = new WorkHomeTypeBean();
        bean02.title = "我是商家";
        typeList.add(bean02);

        WorkHomeTypeBean bean03 = new WorkHomeTypeBean();
        bean03.title = "我是跑腿";
        typeList.add(bean03);

        WorkHomeTypeBean bean04 = new WorkHomeTypeBean();
        bean04.title = "旅游";
        typeList.add(bean04);

        WorkHomeTypeBean bean05 = new WorkHomeTypeBean();
        bean05.title = "司机";
        typeList.add(bean05);

        WorkHomeTypeBean bean06 = new WorkHomeTypeBean();
        bean06.title = "我是店家";
        typeList.add(bean06);

        WorkHomeTypeBean bean07 = new WorkHomeTypeBean();
        bean07.title = "我是服务商";
        typeList.add(bean07);

        WorkHomeTypeBean bean08 = new WorkHomeTypeBean();
        bean08.title = "我的笔记";
        typeList.add(bean08);

        WorkHomeTypeBean bean09 = new WorkHomeTypeBean();
        bean09.title = "志愿者";
        typeList.add(bean09);

        WorkHomeTypeBean bean10 = new WorkHomeTypeBean();
        bean10.title = "备忘录";
        typeList.add(bean10);

        WorkHomeTypeBean bean11 = new WorkHomeTypeBean();
        bean11.title = "资料保存";
        typeList.add(bean11);

        GridLayoutManager manager = new GridLayoutManager(getContext(), 4);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(manager);
        typeAdapter = new WorkHomeTypeAdapter(getContext(), typeList);
        mRecyclerView.setAdapter(typeAdapter);
    }
}
